{% extends 'preheat/base.html' %}

{% block title %}用户管理 - CDN预热平台{% endblock %}

{% block page_title %}用户管理{% endblock %}

{% block content %}
    <div class="mb-4">
        <a href="{% url 'preheat:user_create' %}" class="btn btn-primary">
            <i class="fas fa-plus"></i> 新增用户
        </a>
    </div>

    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>用户名</th>
                            <th>邮箱</th>
                            <th>手机号</th>
                            <th>创建时间</th>
                            <th>最后登录时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for user in users %}
                        <tr>
                            <td>{{ user.username }}</td>
                            <td>{{ user.email|default:'-' }}</td>
                            <td>{{ user.profile.phone|default:'-' }}</td>
                            <td>{{ user.date_joined|date:'Y-m-d H:i:s' }}</td>
                            <td>{{ user.profile.last_login_time|date:'Y-m-d H:i:s'|default:'-未登录过-' }}</td>
                            <td>
                                <a href="{% url 'preheat:user_update' user.pk %}" class="btn btn-sm btn-info" title="编辑">
                                    <i class="fas fa-edit"></i> 编辑
                                </a>
                                <a href="{% url 'preheat:user_password_change' user.pk %}" class="btn btn-sm btn-warning" title="修改密码">
                                    <i class="fas fa-key"></i> 修改密码
                                </a>
                                {% if user.pk != request.user.pk %}
                                <a href="{% url 'preheat:user_delete' user.pk %}" class="btn btn-sm btn-danger" title="删除">
                                    <i class="fas fa-trash"></i> 删除
                                </a>
                                {% else %}
                                <button class="btn btn-sm btn-secondary" disabled title="无法删除当前用户">
                                    <i class="fas fa-trash-alt"></i> 无法删除
                                </button>
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="6" class="text-center">暂无用户数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
{% endblock %}